package com.itboye.sunsun.me.ui;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itboye.sunsun.adapter.SystemAnnounceAdapter;
import com.itboye.sunsun.application.App;
import com.itboye.sunsun.beans.MessageBean;
import com.itboye.sunsun.beans.WoDeZhuTiBean;
import com.itboye.sunsun.constants.SPContants;
import com.itboye.sunsun.custome.XListView;
import com.itboye.sunsun.custome.XListView.IXListViewListener;
import com.itboye.sunsun.network.HttpRequest;
import com.itboye.sunsun.support.BaseFragment;
import com.itboye.sunsun.utils.SPUtils;
import com.itboye.sunsun.volley.MyJsonRequest;
import com.itboye.sunsun.volley.XErrorListener;
import com.itboye.sunsun.volley.XRequestListener;
import com.itboye.sunsunhome.R;

public class MessageXiTongFragmet extends BaseFragment {

	private XListView xlistviewMessge;
	private int pageNum = 1;

	private BaseAdapter adapter;

	private TextView tvMessge;
	List<MessageBean> dataList = new ArrayList<>();
	TextView textStrimg;
	LinearLayout layoutNull;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_messge, container, false);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		tvMessge.setText(R.string.xitong_messge);
		xlistviewMessge.setPullRefreshEnable(false);
		xlistviewMessge.setPullLoadEnable(false);
		// xlistviewMessge.setXListViewListener(new IXListViewListener() {
		//
		// @Override
		// public void onRefresh() {
		// getData();
		// }
		//
		// @Override
		// public void onLoadMore() {
		// pullUp();
		// }
		//
		// });
		// adapter = new ShopCarAdapter(getApplication(), dataList, this);
		// xlistview.setAdapter(adapter);
		// adapter=onGetAdapter();
		adapter = new SystemAnnounceAdapter(dataList);
		xlistviewMessge.setAdapter(adapter);

		getData();

		/*
		 * xlistviewMessge.setOnItemClickListener(new OnItemClickListener() {
		 * 
		 * @Override public void onItemClick(AdapterView<?> parent, View view,
		 * int position, long id) { position--; Intent intent=new
		 * Intent(getActivity(), TieZiDetailActivity.class); ZhuTiItemBean
		 * bean=dataList.get(position); intent.putExtra("fid", bean.getFid());
		 * intent.putExtra("tid", bean.getTid()); intent.putExtra("img",
		 * bean.getImg());
		 * 
		 * intent.putExtra("author", bean.getAuthor());
		 * intent.putExtra("author_id", bean.getAuthorId());
		 * 
		 * startActivity(intent); } });
		 */
	}

	private void getData() {
		MyJsonRequest<List<MessageBean>> request = new MyJsonRequest.Builder<List<MessageBean>>()
				.typeKey("BY_Message_query")
				.apiVer("100")
				.param("uid",
						(String) SPUtils.get(App.ctx, null, SPContants.USER_ID,
								"")).param("msg_type", "1")
				.requestListener(new XRequestListener<List<MessageBean>>() {

					@Override
					public void onResponse(List<MessageBean> arg0) {

						if (arg0 != null) {
							dataList.addAll(arg0);
							adapter.notifyDataSetChanged();
						}
						if (adapter == null || arg0.size()<0) {
							layoutNull.setVisibility(View.VISIBLE);
							xlistviewMessge.setVisibility(View.GONE);
							textStrimg.setText("暂无系统消息");
						}
					}
				}).errorListener(new XErrorListener() {

					@Override
					public void onErrorResponse(Exception exception, int code,
							String msg) {

					}
				}).build();
		HttpRequest.getDefaultRequestQueue().add(request);
	}

}
